package com.ivo.jersey.taskMgr.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;

import javax.naming.directory.SearchResult;

import com.ivo.jersey.pojo.Task;
import com.ivo.jersey.taskMgr.TaskMgr;

public class TaskMgrImpl implements TaskMgr {

	private static Map<String, Task> taskStore = new HashMap<String, Task>();

	@Override
	public String createTask(Task task) {
		String taskID = UUID.randomUUID().toString();
		task.setTaskID(taskID);
		taskStore.put(taskID, task);
		return taskID;
	}

	@Override
	public Task getTask(String taskID) {
		return taskStore.get(taskID);
	}

	@Override
	public void updateTask(String taskID, Task task) {
		taskStore.remove(taskID);
		taskStore.put(taskID, task);
	}

	@Override
	public void deleteTask(String taskID) {
		taskStore.remove(taskID);
	}

	@Override
	public SearchResult serachAllTasks() {
		Iterator iter = taskStore.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next();
			Object key = entry.getKey();
			Object val = entry.getValue();
			System.out.println("key:[" + key + "], val:[" + val + "]");
		}
		return null;
	}
}
